package de.clue.corpus.twitter.bean;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

import org.apache.xmlbeans.XmlException;

import noNamespace.RootDocument;
import noNamespace.TweetDocument;
import noNamespace.TweetDocument.Tweet;

public class TweetLister {

    private File currentXML;
    private ArrayList<Tweet> tweets = new ArrayList<TweetDocument.Tweet>();
    public File getCurrentXML() {
        return currentXML;
    }
    public void setCurrentXML(File currentXML) {
        this.currentXML = currentXML;
        initTweets();
    }
    public ArrayList<Tweet> getTweets() {
        return tweets;
    }
    public void setTweets(ArrayList<Tweet> tweets) {
        this.tweets = tweets;
    }
    private void initTweets() {

        try {
            ArrayList<Tweet> newTweets = new ArrayList<TweetDocument.Tweet>();
            
            RootDocument rootDocument = RootDocument.Factory.parse(getCurrentXML());
            Tweet[] tweetArray = rootDocument.getRoot().getTweetArray();
            newTweets.addAll(Arrays.asList(tweetArray));
            
            setTweets(newTweets);
            
        } catch (XmlException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
    }
    
}
